<template>
    <div>
        <span style="font-size: 14px;margin-left: 20px">共 {{ dataSource.length }} 条</span>
        <el-popover placement="top" trigger="hover" width="100" v-for="(item, index) in dataSource" :key="index">
            <div>
                <div v-for="(item1, index1) in item.clientTodoDescription" :key="index">
                    <div v-if="item1.contentType == '1'">
                        <el-divider v-if="index1 != '0'"></el-divider>
                        {{ item1.content }}
                    </div>
                    <div v-if="item1.contentType == '2'">
                        <el-divider v-if="index1 != '0'"></el-divider>
                        <img :src="item1.imageUrl" class="avatar">
                    </div>
                    <div v-if="item1.contentType == '3'">
                        <el-divider v-if="index1 != '0'"></el-divider>
                        <el-button type="text" @click="downloadHandle(item1.fileName)">下载MP4</el-button>
                    </div>
                    <div v-if="item1.contentType == '4'">
                        <el-divider v-if="index1 != '0'"></el-divider>
                        <el-button type="text" @click="downloadHandle(item1.fileName)">下载文件</el-button>
                    </div>
                    <div v-if="item1.contentType == '5'">
                        <el-divider v-if="index1 != '0'"></el-divider>
                        <div style="display: flex">
                            链接:
                            <el-button type="text" style="padding: 0">{{ item1.linkContent.linkAddress }}</el-button>
                        </div>
                        <div style="display: flex">
                            链接标题:
                            <el-button type="text" style="padding: 0">{{ item1.linkContent.linkTitle }}</el-button>
                        </div>
                        <div style="display: flex">
                            内容简介:
                            <el-button type="text" style="padding: 0">{{ item1.linkContent.content == "" ? "--" : item1.linkContent.content }}</el-button>
                        </div>
                    </div>
                </div>
            </div>
            <div slot="reference" style="padding: 15px;border: 1px solid #ececec;border-radius: 5px;margin-top: 15px">
                <div style="display:flex;font-size: 15px;">
                    <div>任务类型：{{ item.clientTodoType }}</div>
                </div>
                <div style="font-size: 12px;color: #a6a6a6;margin-top: 15px">
                    <span>任务起止时间：{{ item.startTime + "--" + item.endTime }}</span>
                </div>
            </div>
        </el-popover>
    </div>
</template>

<script>
const clientTodoType = [{
    value: '1',
    label: '发微信'
}, {
    value: '2',
    label: '打电话'
}, {
    value: '3',
    label: '拜访'
}, {
    value: '4',
    label: '其他'
}]

export default {
    name: "client_task",
    props: {
        clientInfo: {
            type: Object,
            default: () => {
            }
        }
    },
    data() {
        return {
            dictionary: {
                clientTodoType: clientTodoType,
            },
            fieldType: {
                clientTodoType: "array",
                startTime: "datetime",
                endTime: "datetime"
            },
            dataSource: []
        }
    },
    mounted() {
        this.queryDataHandle()
    },
    methods: {
        queryDataHandle() {
            let that = this
            that.$request("/api/clientTodo/getClientTodoByParams/1_0", {clientId: this.clientInfo.clientId}, "POST").then((data) => {
                let dataSource = []
                data.rows.map((item) => {
                    item.clientTodoDescription = JSON.parse(item.clientTodoDescription)
                    dataSource.push(that.$utils.formatterForForm(item, that.fieldType, that.dictionary))
                })
                that.dataSource = dataSource
            })
        },
        downloadHandle(fileName) {
            let num = fileName.lastIndexOf(".")
            this.$requestFile("/api/clientAtt/downloadFile/1_0", {accessoriesAddress: fileName}, "待办文件" + fileName.substring(num))
        }
    }
}
</script>

<style>
.el-popover {
    width: 200px !important;
}
</style>